from fasc_api.client.corp_client import CorpClient
from fasc_api.client.service_client import ServiceClient
from fasc_api.exception.exceptions import ClientException
from fasc_api.exception.exceptions import ServerException

from init_demo_data import InitDemoData
api_client = InitDemoData.api_client
access_token = ServiceClient.get_access_token_value(api_client)
api_client.set_access_token(access_token)


# 添加企业用户
def add_corp_demo():
    try:
        data = {
            # 企业用户在应用中的唯一标识
            'clientCorpId': InitDemoData.clientCorpId,
            'clientCorpName': '企业名称',
        }
        res = CorpClient.add(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())


# 更新企业用户
def update_corp_demo():
    try:
        data = {
            # 法大大平台为该企业在该应用appId范围内分配的唯一标识
            'openCorpId': InitDemoData.openCorpId,
            'clientCorpId': '企业在应用系统中的唯一标识',
            'clientCorpName': '企业名称',
        }
        res = CorpClient.update(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())

# 删除企业用户
def delete_corp_demo():
    try:
        data = {
            # 法大大平台为该企业在该应用appId范围内分配的唯一标识
            'openCorpId': InitDemoData.openCorpId
        }
        res = CorpClient.delete(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())

# 禁用企业用户
def disable_corp_demo():
    try:
        data = {
            # 法大大平台为该企业在该应用appId范围内分配的唯一标识
            'openCorpId': InitDemoData.openCorpId
        }
        res = CorpClient.disable(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())

# 恢复企业用户
def enable_corp_demo():
    try:
        data = {
            # 法大大平台为该企业在该应用appId范围内分配的唯一标识
            'openCorpId': InitDemoData.openCorpId
        }
        res = CorpClient.enable(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())

# 解绑企业用户账号
def unbind_corp_demo():
    try:
        data = {
            # 法大大平台为该企业在该应用appId范围内分配的唯一标识
            'openCorpId': InitDemoData.openCorpId
        }
        res = CorpClient.unbind(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())

# 获取企业用户授权链接
def get_auth_url_corp_demo():
    try:
        data = {
            # 法大大平台为该企业在该应用appId范围内分配的唯一标识
            'openCorpId': InitDemoData.openCorpId,
            'corpIdentInfo': {
                'corpName': '企业名称全称',
                'corpIdentType': '企业组织类型: corp: 企业, individual_biz: 个体工商户, government: 政府和事业单位, other: 其他类型。',
                'corpIdentNo': '企业统一社会信用代码或各种类型组织的唯一代码',
                'legalRepName': '法定代表人名称(Legal Representative Name)'
            },
            'corpIdentInfoMatch': '是否需要匹配企业身份信息一致,True/False',
            'operatorId': '企业经办人的openUserId',
            'operatorIdentInfo': {
                'userName': '个人用户真实姓名',
                'identType': '证件类型 ：id_card: 身份证 , passport: 护照 , hk_macao: 港澳居民来往内地通行证 , taiwan: 台湾居民来往大陆通行证, 只有携带这个参数，identNo参数才有效。',
                'identNo': '证件号'
            },
            'operatorInfoExtend': {
                'bankAccountNo': '个人银行账户号',
                'mobile': '个人实名手机号'
            },
            'operatorIdentInfoMatch': '是否需要匹配企业经办人身份信息一致,True/False',
            'requestAuthScope': ['ident_info', 'signtask_init','resource_for_sign'],
            'redirectUrl': '重定向地址'
        }
        res = CorpClient.get_auth_url(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())

# 查询企业用户基本信息
def get_detail_corp_demo():
    try:
        data = {
            # 法大大平台为该企业在该应用appId范围内分配的唯一标识
            'openCorpId': InitDemoData.openCorpId
        }
        res = CorpClient.get_detail(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())

# 获取企业用户身份信息
def get_identity_info_corp_demo():
    try:
        data = {
            # 法大大平台为该企业在该应用appId范围内分配的唯一标识
            'openCorpId': InitDemoData.openCorpId
        }
        res = CorpClient.get_identity_info(api_client, data)
        print(res)
    except ClientException as e:
        print(e.__str__())
    except ServerException as e:
        print(e.__str__())

if __name__ == '__main__':
    add_corp_demo()
    update_corp_demo()
    delete_corp_demo()
    disable_corp_demo()
    enable_corp_demo()
    unbind_corp_demo()
    get_auth_url_corp_demo()
    get_detail_corp_demo()
    get_identity_info_corp_demo()
